package com.ekuaitu.kuaitu.activity;

import android.app.Application;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;

import android.widget.ImageView;

import com.ekuaitu.kuaitu.R;
import com.ekuaitu.kuaitu.base.BaseActivity;
import com.ekuaitu.kuaitu.utils.AppManager;
import com.ekuaitu.kuaitu.utils.Rotate3dAnimation;
import com.zhy.autolayout.AutoRelativeLayout;


import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;

public class FestivalActivity extends BaseActivity {

    @BindView(R.id.activity_festival)
    AutoRelativeLayout activityFestival;
    private int depthZ = 0;
    private int duration = 3000;
    private Rotate3dAnimation openAnimation1;
    private Rotate3dAnimation openAnimation2;

    @Override
    public int getLayoutId() {
        return R.layout.activity_festival;
    }

    @Override
    public void initView() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }

    @Override
    protected void onResume() {
        super.onResume();

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        initOpenAnimLeft();
                        initOpenAnimRight();
                        // festivalLeft.startAnimation(openAnimation1);
                        // festivalRight.startAnimation(openAnimation2);
                    }
                });

            }
        }, 1000);
    }

    private void initOpenAnimLeft() {
        // openAnimation1 = new Rotate3dAnimation(0, 65, 0, festivalLeft.getHeight() / 2, depthZ, false);
        openAnimation1.setDuration(duration);
        openAnimation1.setFillAfter(true);
        openAnimation1.setInterpolator(new AccelerateInterpolator());
        openAnimation1.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
             /*   mLogoIv.setVisibility(View.GONE);
                mDescTv.setVisibility(View.VISIBLE);

                //从270到360度，顺时针旋转视图，此时reverse参数为false，达到360度动画结束时视图变得可见
                Rotate3dAnimation rotateAnimation = new Rotate3dAnimation(270, 360, centerX, centerY, depthZ, false);
                rotateAnimation.setDuration(duration);
                rotateAnimation.setFillAfter(true);
                rotateAnimation.setInterpolator(new DecelerateInterpolator());
                mContentRl.startAnimation(rotateAnimation);*/
            }
        });
    }


    private void initOpenAnimRight() {
        //   openAnimation2 = new Rotate3dAnimation(360, 295, festivalRight.getWidth(), festivalRight.getHeight() / 2, depthZ, true);
        //   Log.i("width", festivalRight.getWidth() + "");
        openAnimation2.setDuration(duration);
        openAnimation2.setFillAfter(true);
        openAnimation2.setInterpolator(new AccelerateInterpolator());
        openAnimation2.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Intent intent = new Intent(FestivalActivity.this, MainActivity.class);
                startActivity(new Intent(intent));
                finish();
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        });
    }
}

